{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e2ed1162-0869-4b2f-a86d-f9c9a105fb25",
   "metadata": {},
   "source": [
    "# Python科学计算库Numpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "be66e87b-5d45-43fe-9603-00490033b19a",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "23cb76b7-8b59-48f5-83fa-269126a42d96",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "#创建一个数组\n",
    "array = [1,2,3,4,5]\n",
    "# array + 1 直接执行会报错"
   ]
  },
 {
   "cell_type": "code",
   "execution_count": 12,
   "id": "7e48050c-a380-449e-a0cb-6a15b25b8b42",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'numpy.ndarray'>\n"
     ]
    }
   ],
   "source": [
    "#数组转换为np.array\n",
    "array = np.array(array)\n",
    "print(type(array))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "e45907ea-36fe-4c06-986d-ea8770bc0fd4",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2, 3, 4, 5, 6])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "array2 = array + 1 #np.array可以直接+1,其中所有数据都+1\n",
    "array2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "0b14b1ff-a8fb-4d94-8ad8-6e7427f32e65",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 3,  5,  7,  9, 11])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "array2 + array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "2dbb023d-d174-41e8-b9a5-f273cb7a6629",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 2,  6, 12, 20, 30])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "array2 * array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "040550e8-8643-42a6-a4d9-d68872a7a746",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "array[0] #取值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "2d2e64b8-c226-485b-8299-002daee93d14",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(5,)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "array.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "89cca198-bc41-4fab-86f4-03f72787ba2b",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6]])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array([[1,2,3],[4,5,6]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4394ef46-e0b0-4042-89df-24e1ab695078",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
